using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation.Server;

namespace TFS.Kanban.VS2010
{
    public class UserService : IUserService
    {
        public IEnumerable<Identity> GetUsers(IServiceProvider projectCollection)
        {
            var groupSecurityService = (IGroupSecurityService)projectCollection.GetService(typeof(IGroupSecurityService));
            var SIDS = groupSecurityService.ReadIdentity(SearchFactor.AccountName, "Project Collection Valid Users", QueryMembership.Expanded);
            var userId = groupSecurityService.ReadIdentities(SearchFactor.Sid, SIDS.Members, QueryMembership.Expanded);
            
            var query = from s in userId
                        where s.Type == IdentityType.WindowsUser
                        select s;

            return query.ToList();
        }
    }
}